package com.example.springbatch.job;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by Liaopan on 2018/9/6.
 */
@Slf4j
@Component
public class JobCompletionNotificationListener extends JobExecutionListenerSupport {

    static Date startTime = null;

    @Override
    public void beforeJob(JobExecution jobExecution) {
        log.info("job start----" + DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        startTime = new Date();
        super.beforeJob(jobExecution);
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        log.info("job done!----count :" + BatchConfiguration.count);
        log.info("start time: " + DateFormatUtils.format(startTime,"yyyy-MM-dd HH:mm:ss"));
        log.info("end time: " + DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        super.afterJob(jobExecution);
    }
}
